﻿Ext.define('Examples.autotree.menuitem.metadata.Metadata', {
    extend: 'Happy.metadata.Metadata',
    singleton: true,

    constructor: function () {
        var me = this;

        me.data = {
            namespace: 'Examples.autocrud',
            name: 'MenuItem',
            plural: 'MenuItems',
            displayName: '菜单',
            summaryProperty: 'Name',
            isTree: true,
            proxy: {
                actionMethods: {
                    create: 'GET',
                    read: 'GET',
                    update: 'GET',
                    destroy: 'GET'
                },
                api: {
                    fetch: 'app/MenuItem/server/Read.aspx'
                }
            },
            treeProxy: {
                actionMethods: {
                    create: 'GET',
                    read: 'GET',
                    update: 'GET',
                    destroy: 'GET'
                },
                api: {
                    create: 'app/MenuItem/server/create.txt',
                    read: 'app/MenuItem/server/ReadTree.aspx',
                    update: 'app/MenuItem/server/update.txt',
                    destroy: 'app/MenuItem/server/destroy.txt'
                }
            },
            model: {
                serverRootId: '\\'
            },
            treeModel: {
                serverRootId: '\\'
            },
            treeStore: {
                defaultRootId: '\\'
            },
            treeGrid: {
                'config-tbar-edit': { remoteLoad: false }
            },
            properties: {
                Id: {
                    name: 'Id',
                    dataType: "Guid",
                    showInGrid: false,
                    showInTreeGrid: false,
                    showInForm: false
                },
                Name: {
                    name: 'Name',
                    displayName: '名称',
                    dataType: "String",
                    treeColumnConfig: {
                        xtype: 'treecolumn',
                        flex: 1
                    }
                },
                ParentId: {
                    name: 'ParentId',
                    displayName: '父菜单',
                    dataType: "Guid",
                    showInGrid: false,
                    showInTreeGrid: false,
                    showInForm: true,
                    foreignReference: {
                        metadata: me
                    },
                    editorConfigFns: [
                        Happy.metadata.EditorConfigFns.treeComboBoxConfigFn,
                        function (metadata, property, editorConfig) {
                            Ext.merge(editorConfig, {
                                treeNodeRenderer: function (values) {
                                    var level = 0;
                                    if (values.Id && values.Id != '\\') {
                                        level = values.Id.split('\\').length - 1;
                                    }

                                    return Ext.String.repeat('&nbsp;', 4 * level) + values.Name;
                                }
                            });
                        }
                    ]
                }
            }
        };

        me.callParent(arguments);
    }
});